<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Task extends Model
{
    use SoftDeletes;
    protected $guarded = ['id'];

    

    public function user()
    {
    	return $this->belongsTo(User::class);
    }

    public function client()
    {
        return $this->belongsTo(Client::class);
    }

    public function worker()
    {
        return $this->belongsTo(User::class,'worker_id');
    }

   
    
    public function replies()
    {
        return $this->hasMany(TaskReply::class);
    }

   
    public function comment()
    {
        return $this->hasOne(TaskComment::class);
    }

    public function car()
    {
        return $this->belongsTo(ClientCar::class,'car_id');
    }   

    public function service()
    {
        return $this->hasMany(TaskService::class);
    }

    public function depart()
    {
        return $this->hasMany(TaskDepart::class);
    }

    public function maintain()
    {
        return $this->belongsTo(MaintainType::class,'maintain_id');
    }

    public function getStatusTxtAttribute()
    {
        $status_arr['1']   = '待处理';
        $status_arr['50']  = '处理中';
        $status_arr['75']  = '等配件';
        $status_arr['100'] = '已完成';
        $status_arr['200'] = '已评价';
        return $status_arr[$this->status];
    }

    public function getStatusStyleAttribute()
    {
        $status_arr['1']   = 'info';
        $status_arr['50']  = 'primary';
        $status_arr['75']  = 'info';
        $status_arr['100'] = 'success';
        $status_arr['200'] = 'purple';
        return $status_arr[$this->status];
    }
}
